VMS Help  —  CC  Language topics, Data Types
  The data type of an object must be specified in its declaration.
  The fundamental data types are the scalar types:

  short int           16-bit signed integer
  signed short int    16-bit signed integer
  unsigned short int  16-bit unsigned integer
  int                 32-bit signed integer
  signed int          32-bit signed integer
  unsigned int        32-bit unsigned integer
  long int            32-bit signed integer
  signed long int     32-bit signed integer
  unsigned long int   32-bit unsigned integer
  long long int       64-bit signed integer
  signed long long int     64-bit signed integer
  unsigned long long int   64-bit unsigned integer
  char                8-bit signed integer
  signed char         8-bit signed integer
  unsigned char       8-bit unsigned integer
  wchar_t             Long character (32-bit unsigned integer)
  float               32-bit (single-precision) floating-point number
  double              64-bit (double-precision) floating-point number
  long double         128-bit (double-precision) floating-point
                      number
  long float          Interchangeable with double, but usage is
                      obsolete
  _Bool               An unsigned int that has the value 0 or 1
  _Imaginary          A C99-specified data type.  In VSI C, use of
                      the _Imaginary keyword produces a warning,
                      which is resolved by treating it as an ordinary
                      identifier.
  _Complex            C99-specified data type available in all three
                      precisions:  float _Complex, double _Complex,
                      or long double _Complex.  A complex type has
                      the same representation and alignment
                      requirements as an array type containing
                      exactly two elements of the corresponding real
                      type; the first element is equal to the real
                      part, and the second element to the imaginary
                      part, of the complex number.

                      Note:  This complex data type is similar to the
                      Fortran type, and has an associated header
                      file, <complex.h>.  Although the fundamental
                      complex data types are implemented in the
                      compiler, the run-time support will not be
                      available until an OpenVMS Alpha release
                      following Version 7.3.

  The signed keyword is the default.  Declaring an object with int,
  for example, is equivalent to declaring it with signed int.
  However, char declarations should be explicitly declared, as the
  compiler offers command-line options to change the default.  If in
  doubt, use signed char over char because signed char is more
  portable.

  Strings are arrays of characters terminated by the null character
  (\0).

  Also, view the contents of the <ints.h> header file for definitions
  of platform-specific integer types.

1  –  Array

  An array is an aggregate of subscripted elements of the same type.
  Elements of an array can have one of the fundamental data types or
  can be structures, unions, or other arrays (multidimensional
  arrays).  An array is declared using square brackets.  The
  following example declares array1 to be an array of 10 integers.
  The valid subscripts for array1 range from 0 to 9.

       int array1[10];

  The next example declares array2 to be a two-dimensional (2 by 3)
  array of integers:

       int array2[2][3];

  The elements are stored in row-major order as follows:

       array2[0][0], array2[0][1], ...  array2[1][2].

2  –  enum

  An enumerated type is used to restrict the possible values of an
  object to a predefined list.  Elements of the list are called
  enumeration constants.

  The main use of enumerated types is to explicitly show the symbolic
  names, and therefore the intended purpose, of objects that can be
  represented with integer values.  Objects of enumerated type are
  interpreted as objects of type signed int, and are compatible with
  objects of other integral types.  The compiler automatically
  assigns integer values to each of the enumeration constants,
  beginning with 0.

  An enumerated type is a set of scalar objects that have type names.
  Variables are declared with enum specifiers in the place of the
  type specifier.  An enumerated type can have one of the following
  forms:

       enum { enumerator,...  }
       enum tag { enumerator,...  }
       enum tag

  Each enumerator defines a constant of the enumerated type (tag).
  The enumerator list forms an ordered list of the type's values.
  Each enumerator has the form "identifier [= expression]", where the
  "identifier" is the name to be used for the constant value and the
  optional "expression" gives its integer equivalent.  If a tag
  appears but no list of enumerators, the enum-specifier refers to a
  previous definition of the enumerated type, identified by the tag.

  The following example declares an enumerated object
  'background_color' with a list of enumeration constants:

  enum colors { black, red, blue, green, } background_color;

  Later in the program, a value can be assigned to the object
  'background_color':

  background_color = red;

  In this example, the compiler automatically assigns the integer
  values as follows:  black = 0, red = 1, blue = 2, and green = 3.
  Alternatively, explicit values can be assigned during the
  enumerated type definition:

  enum colors { black = 5, red = 10, blue, green = black+2 };

  Here, black equals the integer value 5, red = 10, blue = 11, and
  green = 7.  Note that blue equals the value of the previous
  constant (red) plus one, and green is allowed to be out of
  sequential order.

  Because the ANSI C standard is not strict about assignment to
  enumerated types, any assigned value not in the predefined list is
  accepted without complaint.

3  –  Pointer

  A pointer in C is a variable that holds the address of another
  variable.  Pointers are declared with the asterisk operator.  For
  example:

       int i, *ip, *np;       /* i IS AN INTEGER, ip AND np ARE
                                 POINTERS TO INTEGERS           */

       The following operations are permitted on pointers:

       o  Assigning an address to the pointer (as in ip = &i;)

       o  Fetching the object of the pointer (by dereferencing the
          pointer) with the asterisk operator (i = *ip;, which
          assigns the addressed integer to i)

       o  Adding (as in ip += 5;, which makes ip point to the object
          that is five longwords away from the initial address in ip)

       o  Subtracting (as in i = np - ip;, which gives the number of
          objects separating the objects pointed to by np and ip)

4  –  Structure

  A structure is an aggregate of members whose data types can differ.
  Members can be scalar variables, arrays, structures, unions, and
  pointers to any object.  The size of a structure is the sum of the
  sizes of its members, which are stored in the order of their
  declarations.  Structures are defined with the keyword struct,
  followed by an optional tag, followed by a structure-declaration
  list in braces.  The syntax is:

       struct [identifier] { struct-declaration ...  }

  Each struct-declaration is a type specifier (type keyword, struct
  tag, union tag, enum tag, or typedef name) followed by a list of
  member declarators:

       type-specifier member-declarator,...  ;

  Each member declarator defines either an ordinary variable or a bit
  field:

       declarator
  or
       [declarator] :  constant-expression

  The following example declares a new structure employee with two
  structure variables bob and susan of the structure type employee:

  struct employee {
     char *name;
     int   birthdate; /* name, birthdate, job_code, and salary are */
     int   job_code;  /* treated as though declared with const.    */
     float salary;
     };

  struct employee bob, susan;

5  –  typedef

   Use the typedef keyword to define an abbreviated name, or
   synonym,  for a lengthy type definition.  Grammatically,
   typedef is a storage-class specifier, so it can precede any valid
   declaration.  In  such  a declaration, the identifiers name types
   instead of variables. For  example:

       typedef char CH, *CP, STRING[10], CF();

   In the scope of this declaration, CH is a synonym for "character,"
   CP  for "pointer to character," STRING for "10-element array of
   characters," and CF for "function returning a character." Each of
   the  type definitions can be used in that scope to declare
   variables. For example:

       CF     c;       /* c IS A FUNCTION RETURNING A CHARACTER */
       STRING s;       /* s IS A 10-CHARACTER STRING            */

6  –  Union

  A union is an aggregate of members whose data types can differ.
  Members can be scalar variables, arrays, structures, unions, and
  pointers to any object.  The size of a union is the size of its
  longest member plus any padding needed to meet alignment
  requirements.  All its members occupy the same storage.  Unions are
  defined with the union keyword, followed by an optional tag,
  followed by a union-declaration list in braces.  The syntax is:

       union [identifier] { union-declaration ...  }

  Each union-declaration is a type specifier (type keyword, struct
  tag, union tag, enum tag, or typedef name) followed by a list of
  member declarators:

       type-specifier member-declarator,...  ;

  Each member declarator defines either an ordinary variable or a bit
  field:

       declarator
  or
       [declarator] :  constant-expression

  Once a union is defined, a value can be assigned to any of the
  objects declared in the union declaration.  For example:

       union name {
         dvalue;
         struct x { int value1; int value2; };
         float fvalue;
       } alberta;

       alberta.dvalue = 3.141596; /*Assigns pi to the union object*/

 Here, alberta can hold a double, struct, or float value.  The
 programmer has responsibility for tracking the current type
 contained in the union.  The type is maintained until explicitly
 changed.  An assignment expression can be used to change the type of
 value held in the union.

7  –  Void

  You can use the void data type to declare functions that do not
  return a value.  Functions declared to be of this type cannot
  contain return statements and cannot be used in statements where a
  return value is expected.  The void data type can be used in the
  cast operation if casting to a "function without a return value
  ...".  You can also use the void data type with pointers.
Close Help